<template>
  <basic-container>
    <avue-crud :option="option" v-model:search="search" v-model:page="page" v-model="form" :table-loading="loading"
      :data="data" :before-open="beforeOpen" ref="crud" @search-change="searchChange" @search-reset="searchReset"
      @selection-change="selectionChange" @current-change="currentChange" @size-change="sizeChange"
      @refresh-change="refreshChange" @on-load="onLoad">
      <template #isPass="{ row }">
        <el-tag v-if="row.isPass == 0" type="danger">
          不及格
        </el-tag>
        <el-tag v-else type="success">
          及格
        </el-tag>
      </template>
      <template #status="{ row }">
        <div v-if="row.status == 1">待办理</div>
      </template>
      <template #hasChild="{ row }">
        <el-link type="primary" @click="commitResult(row)">确认</el-link>
      </template>
      <template #menu-right="row">
        <el-button type="primary" size="small"
          @click="handler_start_subjectiveResult('department')">综合素质部门评价</el-button>
        <el-button type="primary" size="small" @click="handler_start_subjectiveResult('product')">综合素质型号评价</el-button>
        <el-button type="primary" size="small" @click="handler_start_subjectiveResult('teacher')">综合素质师傅评价</el-button>
      </template>
      <template #status-search="{ disabled, size }">
        <el-select v-model="search.status" placeholder="状态" style="width: 240px" clearable>
          <el-option key="1" label="待办理" value="1" />
          <el-option key="0" label="已办理" value="0" />
        </el-select>
      </template>
      <template #isPass-search="{ disabled, size }">
        <el-select v-model="search.isPass" placeholder="是否及格" style="width: 240px" clearable>
          <el-option key="0" label="不及格" value="0" />
          <el-option key="1" label="及格" value="1" />
        </el-select>
      </template>
    </avue-crud>
    <EvaluationDialog ref="subjectivestartRef" :detail="examDetail" :type="subjectiveType" />
    <CommitDialog ref="subjectivecommitRef" :detail="commitDataDetail" :type="subjectiveType" />
  </basic-container>
</template>

<script>
import { getList, subjectiveResultStart } from '@/api/position/positionAssessResultSubjective';
import { getExamDetail } from '@/api/position/positionAssessResult';
import EvaluationDialog from './com/subjectivestart.vue';
import CommitDialog from './com/subjectivecommit.vue';
import option from './option_sub';
import ExamDialog from './com/examDialog.vue';
import { ElNotification } from 'element-plus'

export default {
  components: { ExamDialog, EvaluationDialog, CommitDialog },
  data() {
    return {
      page: {
        pageSize: 10,
        currentPage: 1,
        total: 0
      },
      option,
      search: {},
      loading: false,
      data: [],
      form: {},
      examDetail: {},
      commitDataDetail:{},
      nextExamId: '',
      selectList: [],
      subjectiveType: ''
    };
  },
  methods: {
    async getList() {
      this.loading = true;
      const res = await getList(this.page.currentPage, this.page.pageSize, this.search);
      this.data = res.data.data.records;
      this.page.total = res.data.data.total;
      this.loading = false;
    },
    beforeOpen(done, type) {
      if (['edit'].includes(type)) {

      }
      done();
    },
    searchChange(form, done) {
      this.getList();
      done();
    },
    searchReset() {
    },
    selectionChange(list) {
      this.selectList = list;
    },
    currentChange() {
    },
    sizeChange() {
    },
    refreshChange() {
    },
    onLoad() {
      this.getList();
    },
    /**
     * 确定
     */
    commitResult(rowData) {
      this.commitDataDetail=rowData;
      this.$refs.subjectivecommitRef.open()
    },
    handler_start_subjectiveResult(type) {
      if (this.selectList.length == 0) {
        ElNotification({
          title: '提示',
          type: 'warning',
          message: h('i', { style: 'color: teal' }, '请选择一个考核'),
        })
      } else {
        console.log(type, this.selectList[0]);
        this.examDetail = this.selectList[0];
        this.subjectiveType = type;
        this.$refs.subjectivestartRef.open()
      }
    }
  }
};
</script>

<style lang="scss" scoped>
.q-cxt {
  display: flex;

  .q-c {
    width: 200px;
  }

  .q-list {
    flex: 1
  }

  .q-option {
    width: 200px;
  }
}
</style>
